const formatTime = d => {
  var hours = new Date(d).getHours() - 8;
  if (hours > 0) {
    return formatHour(new Date(d));
  } else {
    return formatMinute(new Date(d));
  }
}

const formatHour = date => {
  const hour = date.getHours() - 8
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [hour, minute, second].map(formatNumber).join(':')
}

const formatMinute = date => {
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime
}